//
//  RootViewController.m
//  UIpicker
//
//  Created by dllo on 15/12/11.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"

@interface RootViewController ()<UIPickerViewDataSource, UIPickerViewDelegate>

@property (nonatomic, retain) NSArray *month;
@property (nonatomic, retain) NSArray *day;

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    // 创建一个pickerView
    UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(50, 100, 275, 200)];
    picker.showsSelectionIndicator = YES;
    picker.dataSource = self;
    picker.delegate = self;
    picker.backgroundColor = [UIColor colorWithRed:0.988f green:0.996f blue:0.745f alpha:1.0];
    picker.layer.borderWidth = 1;
    picker.layer.cornerRadius = 10;
    
    self.month = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12",nil];
    self.day = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12", @"13", @"14", @"15", @"16", @"17", @"18", @"19", @"20", @"21", @"22", @"23", @"24", @"25", @"26", @"27", @"28", @"29", @"30", nil];
    
    [self.view addSubview:picker];
    
    
    
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (component == 0) {
        return self.month.count;
    } else {
        return self.day.count;
    }
}

// 设置每列宽度
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
    if (component == 0) {
        return 100;
    }
    return 175;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (component == 0) {
        NSLog(@"%@", self.month[row]);
    } else {
        NSLog(@"%@", self.day[row]);
    }
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (component == 0) {
        return [self.month objectAtIndex:row];
    } else {
        return [self.day objectAtIndex:row];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
